﻿<UserControl x:Class="SqlExport.View.StatusPanel.StatusPanelView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:seui="clr-namespace:SqlExport"
             xmlns:vm="clr-namespace:SqlExport.ViewModel"
             xmlns:v="clr-namespace:SqlExport.View.StatusPanel"
             Padding="0" 
             Margin="0">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary>
                    <ResourceDictionary.MergedDictionaries>
                        <ResourceDictionary Source="/SqlExport.Ui;component/Themes/Generic.xaml" />
                    </ResourceDictionary.MergedDictionaries>
                </ResourceDictionary>
            </ResourceDictionary.MergedDictionaries>

            <vm:MessageListViewModel x:Key="ViewModel" />
            <v:ConnectionDescriptionValueConverter x:Key="ConnectionDescriptionValueConverter"/>
            <v:ConnectionColourValueConverter x:Key="ConnectionColourValueConverter"/>
            <v:ElapsedTimeValueConverter x:Key="ElapsedTimeValueConverter"/>
            <v:SelectedTextValueConverter x:Key="SelectedTextValueConverter"/>
            <v:RecordCountValueConverter x:Key="RecordCountValueConverter"/>

            <Style TargetType="{x:Type Label}">
                <Setter Property="Padding" Value="1,0,1,0" />
                <Setter Property="VerticalAlignment" Value="Center" />
            </Style>

            <Style BasedOn="{StaticResource {x:Static ToolBar.SeparatorStyleKey}}" TargetType="Separator">
                <Setter Property="Margin" Value="2,0"/>
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <UserControl.DataContext>
        <Binding Path="StatusPanelViewModel" Source="{StaticResource Locator}"/>
    </UserControl.DataContext>
    <Grid>
        <StatusBar Background="Transparent">
            <StatusBar.ItemsPanel>
                <ItemsPanelTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                            <ColumnDefinition Width="Auto"/>
                        </Grid.ColumnDefinitions>
                    </Grid>
                </ItemsPanelTemplate>
            </StatusBar.ItemsPanel>
            <StatusBarItem>
                <StackPanel Orientation="Horizontal">
                    <ToggleButton x:Name="ConnectionsButton" 
                    ToolTip="Select Connection"
                    Content="{StaticResource ArrowUp}">
                    </ToggleButton>
                    <Popup IsOpen="{Binding IsChecked, ElementName=ConnectionsButton}" 
                       PlacementTarget="{Binding ElementName=ConnectionsButton}"
                       VerticalOffset="5" 
                       HorizontalOffset="-10" 
                       StaysOpen="False" Placement="Top">
                        <ListView ItemsSource="{Binding Databases}" Style="{StaticResource SelectionPopupStyle}">

                        </ListView>
                    </Popup>
                    <Label Margin="3,0,3,0"
                       Content="{Binding Connection, Converter={StaticResource ConnectionDescriptionValueConverter}}" 
                       Foreground="{Binding Connection,Converter={StaticResource ConnectionColourValueConverter}}"/>
                    <Separator/>
                </StackPanel>
            </StatusBarItem>
            <StatusBarItem Grid.Column="1">
                <Label Content="{Binding Status}" />
            </StatusBarItem>
            <StatusBarItem Grid.Column="2">
                <StackPanel Orientation="Horizontal">
                    <Separator/>
                    <Label Content="{Binding RecordCount, Converter={StaticResource RecordCountValueConverter}}" MinWidth="90" />
                    <Separator/>
                    <Label Content="{Binding ElapsedTime, Converter={StaticResource ElapsedTimeValueConverter}}" MinWidth="90" />
                    <Separator/>
                    <Label Content="{Binding SelectedTextRange, Converter={StaticResource SelectedTextValueConverter}}" Padding="1,0,3,0" />
                </StackPanel>
            </StatusBarItem>
        </StatusBar>
    </Grid>
</UserControl>
